#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
char a[1000010];
int main()
{
    int t = 0;
    scanf("%d", &t);
    while (t--)
    {
        long long n = 0;
        scanf("%lld", &n);
        getchar();
        scanf("%s", a);
        long long max_light = 0, max_dark = 0, now_light = 0, now_dark = 0;
        for (long long i = 0; i < n; i++)
        {
            if (a[i] == '1' || a[i] == '2')
            {
                if (now_dark > max_dark) max_dark = now_dark;
                now_dark = 0;
                now_light++;
            }
            else
            {
                if (now_light > max_light) max_light = now_light;
                now_light = 0;
                now_dark++;
            }
        }
        if (now_dark > max_dark) max_dark = now_dark;
        if (now_light > max_light) max_light = now_light;
        if (max_dark >= max_light) printf("%lld\n", max_dark);
        else printf("%lld\n", max_light);
    }
    return 0;
}

//int cut[100010];
//int main()
//{
//	int max = 0, n = 0;
//	scanf("%d", &n);
//	for (int i = 0; i < n; i++)
//	{
//		int input = 0;
//		scanf("%d", &input);
//		if (input > max) max = input;
//		cut[input]++;
//	}
//	for (int i = 0; i <= max; i++)
//	{
//		printf("%d\n", cut[i]);
//	}
//	return 0;
//}